#include "dpi.h"

#include <SDL2/SDL.h>

#ifdef _WIN32
#include <Windows.h>
#include <ShellScalingApi.h>
#endif

static float x_factor = 1.f, y_factor = 1.f;

void dpi_init() {

#ifdef _WIN32
		SetProcessDpiAwareness(PROCESS_PER_MONITOR_DPI_AWARE);

		HDC dc = GetDC(NULL);

		float standard_px_per_logical_inch = 96.f;

		x_factor = GetDeviceCaps(dc, LOGPIXELSX) / standard_px_per_logical_inch;
		y_factor = GetDeviceCaps(dc, LOGPIXELSY) / standard_px_per_logical_inch;

		ReleaseDC(NULL, dc);
#endif

}

float dpi_x(float x) {
	return x * x_factor;
}

float dpi_y(float y) {
	return y * y_factor;
}

int dpi_xi(int x) {
	return (int)(x * x_factor);
}

int dpi_yi(int y) {
	return (int)(y * y_factor);
}